<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserTable extends Migration
{
    public function up()
    {
        //用户表
        Schema::create('user', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username',20)->unique()->comment('用户名');
            $table->string('password')->comment('密码');
            $table->string('nick_name',20)->nullable()->comment('昵称');
            $table->string('id_type',20)->nullable()->comment('证件类型');
            $table->string('id_name',20)->nullable()->comment('证件姓名');
            $table->string('id_num',20)->nullable()->comment('证件号码');    // 一个证件?个限制
            $table->string('id_img_1')->nullable()->comment('证件照片_正');
            $table->string('id_img_2')->nullable()->comment('证件照片_反');
            $table->string('pay_password')->nullable()->comment('支付密码');
            $table->string('mobile',13)->nullable()->comment('手机');         //->unique()
            $table->string('email',50)->nullable()->comment('邮箱');          //->unique()
            $table->string('addr_id',50)->nullable()->comment('用户地址ID');
            $table->string('avatar')->nullable()->comment('用户头像');
            $table->string('recommend',20)->nullable()->comment('推荐人ID');
            $table->unsignedTinyInteger('level')->default(0)->comment('用户等级');
            $table->unsignedDecimal('cash',10,2)->default(0)->comment('现金积分');
            $table->unsignedDecimal('sp',10,2)->default(0)->comment('购物积分');
            $table->unsignedTinyInteger('status')->default(2)->comment('1禁止,2正常');
            $table->ipAddress('last_ip')->nullable()->comment('最后登录IP');
            $table->unsignedInteger('login_count')->default(0)->comment('登录次数');
            $table->timestamp('last_login')->nullable()->comment('最后登录时间');
            $table->boolean('deleted')->default(false)->comment('删除');
            $table->rememberToken()->comment('记住登录状态');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('user');
    }
}
